package com.labreeze.spring.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class FileOperator {
	
	private BufferedReader reader=null;
	private PrintWriter pw=null;
	
	
	//读文件模板
	public void initReadFile(String fileName) throws Exception{
		File file=new File(fileName);
		InputStream in=new FileInputStream(file);
		reader = new BufferedReader(
				new InputStreamReader(in));
		String line = null;
		while ((line = reader.readLine()) != null) {
			
		}
		if(reader!=null){
			reader.close();
			reader=null;
		}
	}
	
	//写文件模板
	public void initFile(String fileName) throws Exception{
		File file=new File(fileName);
		pw=new PrintWriter(file);
	}
	
	public void writeFile(String line){
		if(!line.endsWith("end")){
			pw.println(line);
		}
	}
	
	public void closeFile(){
		if(pw!=null){
			pw.close();
		}
	}

}
